package com.ttsx.listener;

import cn.hutool.core.bean.BeanUtil;
import com.ttsx.mapper.CategoryMapper;
import com.ttsx.pojo.entity.Category;
import com.ttsx.pojo.vo.CategoryEeVO;
import lombok.extern.slf4j.Slf4j;

/**
 * 分类导入数据监听器
 *
 * @author wb
 * @since 2025-09-16
 */
@Slf4j
public class CategoryListener extends BaseListener<CategoryEeVO, CategoryMapper> {
    public CategoryListener(CategoryMapper mapper) {
        super(mapper);
    }

    @Override
    protected void saveData() {
        log.info("{} >> {}条数据，开始存储数据库！", this.getClass().getSimpleName(), cachedDataList.size());
        cachedDataList.forEach(item -> {
            Category category = BeanUtil.copyProperties(item, Category.class, "id");
            mapper.insert(category);
        });
    }
}
